package com.kejiguan.ui.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.kejiguan.ui.R;
import com.kejiguan.ui.model.ExhibitionRunData;

import java.util.List;

/**
 * Created by YYY on 2016/4/29.
 */
public class NeItemRunDataMemuAdapter extends RecyclerView.Adapter<NeItemRunDataMemuVH>{

    public Context mContext;
    private List<ExhibitionRunData> neItemRunDatas;
    private LayoutInflater mInflater;
    private View.OnClickListener onClickListener;
    private ExhibitionRunData selectArea;

    public NeItemRunDataMemuAdapter(Context context,List<ExhibitionRunData> neItemRunDatas)
    {
        this.mContext = context;
        this.neItemRunDatas = neItemRunDatas;
        mInflater=LayoutInflater.from(mContext);
        if (neItemRunDatas!=null&&neItemRunDatas.size()>0)
        {
            selectArea=neItemRunDatas.get(0);
        }
    }
    @Override
    public NeItemRunDataMemuVH onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView=mInflater.inflate(R.layout.fragment_neitem_rundata_menu_itemlayout,null);
        return new NeItemRunDataMemuVH(itemView);
    }

    @Override
    public void onBindViewHolder(NeItemRunDataMemuVH holder, int position) {

        ExhibitionRunData displayArea=neItemRunDatas.get(position);
        holder.menuName.setText(displayArea.getDisplayName());

        if (displayArea.getDisplayId().equals(selectArea.getDisplayId()))
        {
            holder.menuName.setBackgroundResource(R.mipmap.display_menu_bg1);
        }else
        {
            holder.menuName.setBackgroundResource(R.drawable.display_menu_bg);
        }

        if (null!=onClickListener)
        {
            holder.menuName.setTag(R.id.recyclerview_item_position,position);
            holder.menuName.setOnClickListener(onClickListener);
        }

    }

    @Override
    public int getItemCount() {
        if (neItemRunDatas==null)
        {
            return 0;
        }else
        {
            return neItemRunDatas.size();
        }
    }

    public void setOnClickListener(View.OnClickListener onClickListener) {
        this.onClickListener = onClickListener;
    }

    public void setSelectArea(int position)
    {
        selectArea=neItemRunDatas.get(position);
        notifyDataSetChanged();
    }

    public ExhibitionRunData getSelectArea() {
        return selectArea;
    }

}
